package com.kk.crowd.handler;

import com.kk.crowd.entity.vo.DetailProjectVO;
import com.kk.crowd.entity.vo.PortalTypeVO;
import com.kk.crowd.entity.vo.ProjectVO;
import com.kk.crowd.service.api.ProjectProviderService;
import com.kk.crowd.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ProjectProviderHandler {

    @Autowired
    private ProjectProviderService projectProviderService;


    @RequestMapping("/get/project/detail/remote/{projectId}")
    public ResultEntity<DetailProjectVO> getDetailProjectVORemote(@PathVariable("projectId")Integer projectId){
        try {
            DetailProjectVO detailProjectVO = projectProviderService.getDetailProjectVO (projectId);
            return ResultEntity.successWithoutData (detailProjectVO);
        } catch (Exception e) {
            e.printStackTrace ( );
            return ResultEntity.failed(e.getMessage());
        }
    }

    /**
     * 返回首页类别项目数据
     * @return
     */
    @RequestMapping("/get/portal/type/project/data/remote")
    public ResultEntity<List<PortalTypeVO>> getPortalTypeProjectDataRemote(){
        try {
            List<PortalTypeVO> portalTypeVOList = projectProviderService.getPortalTypeVO ( );

            return ResultEntity.successWithoutData (portalTypeVOList);
        }catch (Exception e){
            e.printStackTrace ();
            return ResultEntity.failed (e.getMessage ());
        }
    }

    /**
     * 执行本地保存
     * @param projectVO
     * @param memberId
     * @return
     */
    @RequestMapping("/save/project/vo/remote")
    ResultEntity<String> saveProjectVORemote(@RequestBody ProjectVO projectVO, @RequestParam("memberId") Integer memberId){
        try {
            // 调用“本地”Service 执行保存
            projectProviderService.saveProject(projectVO,memberId);
            return ResultEntity.successWithoutData ();
        } catch (Exception e) {
            e.printStackTrace ( );
            return ResultEntity.failed (e.getMessage ());
        }
    }
}
